package com.baidu.cleaner.transformer;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

public class DateTransformer implements Transformer {
	private String fromFormat = null;
	private String destFormat = null;

	public String getFromFormat() {
		return fromFormat;
	}

	public void setFromFormat(String fromFormat) {
		this.fromFormat = fromFormat;
	}

	public String getDestFormat() {
		return destFormat;
	}

	public void setDestFormat(String destFormat) {
		this.destFormat = destFormat;
	}

	@Override
	public String transform(String value) throws Exception {
		return DateFormatUtils.format(DateUtils.parseDate(value, this.fromFormat), destFormat);
	}

	public static void main(String[] args) throws Exception {
		DateTransformer t = new DateTransformer();
		t.setFromFormat("yyyy-MM-dd");
		t.setDestFormat("yyyyMMdd");
		System.out.println(t.transform("2012-11-01"));
	}

}
